import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class call implements Callable<Integer> {
    public static int i=100;

    @Override
    public Integer call() throws Exception {
        while (i>0){
            synchronized (Object.class){
                i--;
                System.out.println(Thread.currentThread().getName()+"========"+i);
            }
            Thread.sleep(3);
        }
        return i;
    }

    static class demo{
        public static void main(String[] args) {
            FutureTask<Integer> f1 = new FutureTask<Integer>(new call());
            FutureTask<Integer> f2 = new FutureTask<Integer>(new call());

            Thread a = new Thread(f1, "A");
            Thread b = new Thread(f2, "B");

            a.start();
            b.start();

            try {
                System.out.println(f1.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
            try {
                System.out.println(f2.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }
}
